package com.frame.demo.ui.presenter;

import com.frame.demo.mvp.BasePresenter;
import com.frame.demo.rest.RestError;
import com.frame.demo.rest.model.bean.LoginBean;
import com.frame.demo.rest.service.LoginService;
import com.frame.demo.mvp.BaseObserver;
import com.frame.demo.ui.view.LoginView;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class LoginPresenter extends BasePresenter<LoginView> {
    private LoginService mLoginService;

    @Inject
    public LoginPresenter(LoginService pLoginService) {
        mLoginService = pLoginService;
    }

    public void login(String username, String password) {
        mLoginService.login(username, password)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<LoginBean>(this) {


                    @Override
                    public boolean onFailed(RestError pRestError) {
                        return false;
                    }

                    @Override
                    protected void doOnNext(LoginBean value) {
                        getMvpView().loginSuccess(value);
                    }
                });

    }

}